<?php
/**
 * Created by PhpStorm.
 * User: kcj
 * Date: 2017/6/28
 * Time: 9:41
 */
namespace app\index\model;

use think\Model;
use think\Request;

class Roomlog extends Model
{
    const CREATEMSG="%s %s 创建房间.roomid :%s。";
    const JOINBMSG="%s %s 加入房间前。";
    const JOINAMSG="%s %s 加入房间后。";

    const READYBMSG="%s %s 准备前。";
    const READYAMSG="%s %s 已经准备。";

    const STARTBMSG="%s %s 开始游戏前。";
    const STARTAMSG="%s %s 开始游戏后。";

    const SETMULBMSG="%s %s 选择倍数前。";
    const SETMULAMSG="%s %s 选择倍数 %s。";

    const STARTROUNDBMSG="开始第%s局之前。";
    const STARTROUNDMSG="开始第%s局。";
    
    const FAPIAMSG="第%s局发牌.";

    const REPAIRBMSG="%s %s 补牌前。";
    const REPAIRAMSG="%s %s 补牌后。";

    const OPENBRANDMSG="第%s局开牌前。";
    const OPENBRANDAMSG="第%s局开牌后。";

    const OUTROOMBMSG="%s %s 离开房间前。";
    const OUTROOMAMSG="离开房间后。";

    const OFFLINEBMSG="%s %s 离线前。";
    const OFFLINEAMSG="%s %s 离线后。";

    const TRUSTMSG="%s %s 进行托管。";
    const CANCELTRUSTMSG="%s %s 取消托管。";

    const DISBANDBEFORE="%s %s 发起解散房间前。";
    const DISBANDAFTER="%s %s 发起解散房间后。";

    const DODISBANDBEFORE="%s %s 同意解散房间前。";
    const DODISBANDAFTER="%s %s 同意解散房间后。";

    public function createlog($msg,$info)
    {
        $data['roomsid']=$info["sid"];
        $data['roomid']=$info['id'];
        $data['msg']=$msg;
        $data['info'] = json_encode($info);
        $data['time']=date("Y-m-d H:i:s",time());
        $data['url']= Request::instance()->url(true);
        $this->insert($data);
    }

    public function createroom($info)
    {
        $this->createlog(sprintf(self::CREATEMSG,$info['owner'],$info['seat1']['name'],$info['id']),$info);
    }

    public function joinroombefore($info,$uid,$name)
    {
        $this->createlog(sprintf(self::JOINBMSG,$uid,$name),$info);
    }

    public function joinroomafter($info,$i)
    {
        $this->createlog(sprintf(self::JOINAMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    /**
     * 准备前日志记录
     * @param $info
     * @param $i
     */
    public function readybefore($info,$i)
    {
        $this->createlog(sprintf(self::READYBMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    /***
     * 准备后日志记录
     * @param $info
     * @param $i
     */
    public function readyafter($info,$i)
    {
        $this->createlog(sprintf(self::READYAMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    /**
     * 开始牌局
     * @param $info
     */
    public function startround($info)
    {
        $this->createlog(sprintf(self::STARTROUNDMSG,$info["currentround"]),$info);
    }

    /**
     * 开始牌局
     * @param $info
     */
    public function startroundbefore($info)
    {
        $this->createlog(sprintf(self::STARTROUNDBMSG,$info["currentround"]),$info);
    }

    /**
     * 开始游戏前
     * @param $info
     * @param $i
     */
    public function startbefore($info,$i)
    {
        $this->createlog(sprintf(self::STARTBMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    /**
     * 开始游戏后
     * @param $info
     * @param $i
     */
    public function startafter($info,$i)
    {
        $this->createlog(sprintf(self::STARTAMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    /**
     * 选择倍数前
     * @param $info
     * @param $i
     */
    public function setmulbefore($info,$i)
    {
        $this->createlog(sprintf(self::SETMULBMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    /**
     * 选择倍数后
     * @param $info
     * @param $i
     */
    public function setmulafter($info,$i)
    {
        $this->createlog(sprintf(self::SETMULAMSG,$info["seat$i"]['uid'],$info["seat$i"]['name'],$info["seat$i"]['multiples']),$info);
    }   

    public function fapai($info)
    {
        $this->createlog(sprintf(self::FAPIAMSG,$info['currentround']),$info);
    }

    public function repairbefore($info,$i)
    {
        $this->createlog(sprintf(self::REPAIRBMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function repairafter($info,$i)
    {
        $this->createlog(sprintf(self::REPAIRAMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function openbrand($info)
    {
        $this->createlog(sprintf(self::OPENBRANDMSG,$info['currentround']),$info);
    }

    public function logupdatescores($info,$data1)
    {
        $data['roomsid']=$info["sid"];
        $data['roomid']=$info['id'];
        $data['msg']="更新分数";
        $info['data']=$data1;
        $data['info'] = json_encode($info);
        $data['time']=date("Y-m-d H:i:s",time());
        $data['url']= Request::instance()->url(true);
        $this->insert($data);
    }

    public function openbrandafter($info)
    {
        $this->createlog(sprintf(self::OPENBRANDAMSG,$info['currentround']),$info);
    }

    public function outroombefore($info,$i)
    {
        $this->createlog(sprintf(self::OUTROOMBMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function outroomafter($info)
    {
        $this->createlog(sprintf(self::OUTROOMAMSG),$info);
    }

    public function offlinebefore($info,$i)
    {
        $this->createlog(sprintf(self::OFFLINEBMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function offlineafter($info)
    {
        $this->createlog(self::OFFLINEAMSG,$info);
    }

    public function trust($info,$i)
    {
        $this->createlog(sprintf(self::TRUSTMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function canceltrust($info,$i)
    {
        $this->createlog(sprintf(self::CANCELTRUSTMSG,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function disbandbefore($info,$i)
    {
        $this->createlog(sprintf(self::DISBANDBEFORE,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function disbandafter($info,$i)
    {
        $this->createlog(sprintf(self::DISBANDAFTER,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function dodisbandbefore($info,$i)
    {
        $this->createlog(sprintf(self::DODISBANDBEFORE,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

    public function dodisbandafter($info,$i)
    {
        $this->createlog(sprintf(self::DODISBANDAFTER,$info["seat$i"]['uid'],$info["seat$i"]['name']),$info);
    }

}
